﻿//----------------------------------------------------------------
// Copyright (C) 2009 xxx
//
// 文件名：         CacheManager.cs
// 文件功能描述：   缓存管理，访问或创建缓存;
// 创建日期：       2009/07/21
// 创建人：         xxx
//----------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Configuration;
using System.Reflection;

namespace OurWeb.Dependency
{
    public sealed class CacheManager
    {
        public static object GetDALObject(string className)
        {
            //从缓存获取对象名称，没有则创建缓存
            object dalName = CacheAccess.GetFromCache("DAL");
            object dalObject = CacheAccess.GetFromCache(className);
            
            if (dalName == null || dalObject == null)
            {
                CacheDependency fileDependency = new CacheDependency(HttpContext.Current.Server.MapPath("Web.Config"));
                
                //添加数据访问层名称缓存
                dalName = ConfigurationManager.AppSettings["DAL"];
                CacheAccess.SaveToCache("DAL", dalName, fileDependency);
                
                //添加对象缓存
                string fullClassName = dalName + className;
                dalObject = Assembly.Load(dalName.ToString()).CreateInstance(fullClassName);
                CacheAccess.SaveToCache(className, dalObject, fileDependency);
            }
            
            return dalObject;
        }
    }
}
